{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. 生命倒计时程序\n",
    "    + 你的年龄\n",
    "    + 在这个世界上，你已经存在了____  年  ____  月  ____日  ____ 小时 ____ 分钟____ 小时\n",
    "    + 几个问题\n",
    "        + 你觉得自己能活多久>>>\n",
    "        + 你抽烟吗(yes/no)>>>\n",
    "        + 你经常锻炼吗(yes/no)>>>\n",
    "        + 你熬夜吗(yes/no)>>>\n",
    "        + 。。。(yes/no)>>>\n",
    "    + 你大概还能活___年\n",
    "    ------------------------\n",
    "    #### 需要的知识：time模块 格式化输出 索引和切片 数据类型转换 控制语句if--else"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>012345200106151234\n",
      "你已经存在了18年，222月，967周，6769天，162473小时，9748417分钟，584905055秒，584906007065微秒\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "ID = input('>>>')  # 012345200106151234\n",
    "birth_time = ID[6:14]   #20010615\n",
    "\n",
    "birth_year = int(birth_time[0:4])   #2001\n",
    "birth_month = int(birth_time[4:6])   #06\n",
    "birth_day = int(birth_time[6:])   #15\n",
    "\n",
    "birth_time = datetime(birth_year,birth_month,birth_day)\n",
    "now = datetime.today()\n",
    "\n",
    "ages = now.year-birth_year\n",
    "months = ages * 12 + (now.month-birth_time.month)\n",
    "day = (now - birth_time).days\n",
    "weeks = day // 7\n",
    "hours = day * 24 + now.hour\n",
    "minutes = hours* 60 + now.minute\n",
    "seconds = minutes * 60 + now.second\n",
    "microseconds = seconds * 10**3 + now.microsecond\n",
    "\n",
    "print('你已经存在了{}年，{}月，{}周，{}天，{}小时，{}分钟，{}秒，{}微秒'.format(ages,months,weeks,day,hours,minutes,seconds,microseconds))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. 判断一个字符串是否为回文\n",
    "    + 输入‘abcdedcba’ 是\n",
    "    + 输入'abcddcba' 是\n",
    "    + 输入‘abcddba’ 否"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>abcddba\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "s = input('>>>')\n",
    "if s == s[::-1]:\n",
    "    print(True)\n",
    "else:\n",
    "    print(False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. 判断DNA序列回文结构--进阶\n",
    "    + 输入一段DNA序列，如‘ACCTAGGT’，请判断它是否回文\n",
    "    + [参考资料](https://baike.baidu.com/item/%E5%9B%9E%E6%96%87%E5%BA%8F%E5%88%97)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "DNA = \"ACCTTAGGT\"\n",
    "# DNA = input('请输入DNA序列>>>')\n",
    "flag = True\n",
    "for i in range(len(DNA)//2):\n",
    "    if DNA[i] == \"A\":\n",
    "        if DNA[-(i+1)] != \"T\":flag = False\n",
    "    elif DNA[i] == \"T\":\n",
    "        if DNA[-(i+1)] != \"A\":flag = False\n",
    "    elif DNA[i] == \"C\":\n",
    "        if DNA[-(i+1)] != \"G\":flag = False\n",
    "    elif DNA[i] == \"G\":\n",
    "        if DNA[-(i+1)] != \"C\":flag = False\n",
    "print(flag)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4. 猜数字游戏\n",
    "    + number = 66 让用户输入数字，判断是否相等\n",
    "    + 提示用户猜的数字偏大或偏小\n",
    "    + 判断用户输入是否非法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请猜一下我的体重>>66\n",
      "你猜对了\n",
      "你真棒\n"
     ]
    }
   ],
   "source": [
    "flag = True\n",
    "while flag:\n",
    "    num = 66\n",
    "    a = int(input('请猜一下我的体重>>'))\n",
    "    if a == num:\n",
    "        flag = False\n",
    "        print('你猜对了')\n",
    "        print('你真棒')\n",
    "    elif a > num:\n",
    "        print('你猜错了,大了')\n",
    "    else:\n",
    "        print('你猜错了,小了')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5. 学习成绩评级"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的分数：90\n",
      "90属于A\n"
     ]
    }
   ],
   "source": [
    "while 1:\n",
    "    score = input('请输入你的分数：')\n",
    "    assert score.isdigit()\n",
    "    score = int(score)\n",
    "    if score >= 90:\n",
    "        grade = 'A'\n",
    "    elif score >= 60:\n",
    "        grade = 'B'\n",
    "    else:\n",
    "        grade = '不及格'\n",
    "    print('%d属于%s' % (score,grade))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "7. 输出99乘法口诀表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1 =  1\n",
      "1*2 =  2  2*2 =  4\n",
      "1*3 =  3  2*3 =  6  3*3 =  9\n",
      "1*4 =  4  2*4 =  8  3*4 = 12  4*4 = 16\n",
      "1*5 =  5  2*5 = 10  3*5 = 15  4*5 = 20  5*5 = 25\n",
      "1*6 =  6  2*6 = 12  3*6 = 18  4*6 = 24  5*6 = 30  6*6 = 36\n",
      "1*7 =  7  2*7 = 14  3*7 = 21  4*7 = 28  5*7 = 35  6*7 = 42  7*7 = 49\n",
      "1*8 =  8  2*8 = 16  3*8 = 24  4*8 = 32  5*8 = 40  6*8 = 48  7*8 = 56  8*8 = 64\n",
      "1*9 =  9  2*9 = 18  3*9 = 27  4*9 = 36  5*9 = 45  6*9 = 54  7*9 = 63  8*9 = 72  9*9 = 81\n"
     ]
    }
   ],
   "source": [
    "print(\"\\n\".join([\"  \".join([\"%d*%d = %2d\"%(x,y,x*y) for x in range(1,y+1)]) for y in range(1,10)]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sum = 0\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
